package main

import (
	"context"
	"fmt"
	"go-web-learning/src/05_grpc/2_hello_world/proto_go"
	"google.golang.org/grpc"
	"google.golang.org/grpc/grpclog"
	"net"
)

type Server struct {
}

func (s Server) SayHello(ctx context.Context, request *proto_go.HelloRequest) (res *proto_go.HelloResponse, err error) {
	fmt.Println("---------------------------------------")
	fmt.Println(request)
	fmt.Println("Hello World")
	return &proto_go.HelloResponse{Name: request.Name, Message: "success"}, nil
}

func main() {
	listen, err := net.Listen("tcp", ":8080")
	if err != nil {
		grpclog.Fatalf("Failed to listen: %s", err.Error())
	}
	defer listen.Close()
	s := grpc.NewServer()
	proto_go.RegisterHelloServiceServer(s, &Server{})
	err = s.Serve(listen)
}
